package com.vf.admin.client.service.impl;

import com.vf.admin.client.dao.AppSignUserAlertDao;
import com.vf.admin.client.service.AppSignUserAlertService;
import com.vf.admin.miaodong.entity.AppSignUserAlert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AppSignUserAlertServiceImpl implements AppSignUserAlertService {

    @Autowired
    AppSignUserAlertDao appSignUserAlertDao;

    @Override
    public AppSignUserAlert find(Integer state) {
        return appSignUserAlertDao.find(state);
    }

    @Override
    public void changeStatus(Integer userId) {
        AppSignUserAlert userAlert = appSignUserAlertDao.find(userId);
        if(userAlert != null) {
            if(userAlert.getStatus() == 0) {
                userAlert.setStatus(1);
            } else {
                userAlert.setStatus(0);
            }
            appSignUserAlertDao.update(userAlert);
        } else {
            userAlert = new AppSignUserAlert();
            userAlert.setUserId(userId);
            userAlert.setStatus(1);
            appSignUserAlertDao.add(userAlert);
        }
    }
}
